package edu.pku.sei.transformation.editor.views.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

import edu.pku.sei.modeler.figures.CommonFigure;
import edu.pku.sei.transformation.editor.views.colors.ColorProvider;

public class DomainFigure extends CommonFigure {
	protected LineBorder border;
	public Label nameLabel;
	protected final org.eclipse.swt.graphics.Color FORGROUND_BLUE = ColorProvider
			.getColor(ColorConstants.lightBlue.getRed(),
					ColorConstants.lightBlue.getGreen(),
					ColorConstants.lightBlue.getBlue());
	private final org.eclipse.swt.graphics.Color FORGROUND_RED = ColorProvider
			.getColor(255, 127, 127);
	protected Color color = FORGROUND_BLUE;
	private final String DOMAIN_TITLE = "<<Domain>>";
	private final String ANTI_TITLE = "<<Neg-Domain>>";
	private boolean isFilled = false;

	public DomainFigure() {
		setLayoutManager(new XYLayout());
		border = new LineBorder(FORGROUND_BLUE, 1);
		this.setBorder(border);
		nameLabel = new Label("<<domain>>");
		nameLabel.setFont(FontConstant.ARIAL_12_B);
		this.add(nameLabel);
		setOpaque(false);
		setForegroundColor(FORGROUND_BLUE);
	}

	public void setAnti(boolean isAnti) {
		if (isAnti) {
			this.color = FORGROUND_RED;
			border.setColor(FORGROUND_RED);
			this.setForegroundColor(FORGROUND_RED);
			nameLabel.setText(this.ANTI_TITLE);
		} else {
			this.color = FORGROUND_BLUE;
			border.setColor(FORGROUND_BLUE);
			this.setForegroundColor(FORGROUND_BLUE);
			nameLabel.setText(this.DOMAIN_TITLE);
		}
		if (isFilled) {
			this.setBackgroundColor(color);
		}
	}

	public void setBounds(Rectangle rect) {
		super.setBounds(rect);
		// nameLabel.setLocation(rect.getLocation());
		nameLabel.setSize(nameLabel.getPreferredSize());
		nameLabel
				.setLocation(new Point(
						rect.x
								+ (rect.width - nameLabel.getPreferredSize().width)
								/ 2, rect.y));
	}

	public void fillFigure() {
		this.setBackgroundColor(color);
		this.isFilled = true;
	}

	public void unfillFigure() {
		this.setBackgroundColor(ColorConstants.white);
		this.isFilled = false;
	}

}
